<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/11
  Time: 15:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

%>

<div id="page-content">
  <div class="row">

    <div class="col-lg-12">
      <div class="panel">
        <div class="panel-heading">
          <h3 class="panel-title">请假申请</h3>
        </div>
        <div class="panel-body">
          <div class="form-inline">
            <div class="row">
              <div class="col-sm-12 table-toolbar-left">
                <btn id="btn_add_leave" class="btn btn-primary btn-sm" ${isStart}>
                  <i class="ti-plus"> </i> 新建请假申请
                </btn>
              </div>
            </div>
          </div>
          <div class="table-jqgrid">
            <table id="leave_table"></table>
            <div id="leave_page"></div>
          </div>
        </div>
      </div>
    </div>

  </div>
</div>

<script>

  $(function(){

    init_grid_leave();

  });

  function init_grid_leave() {
    __init_jqgrid('leave_table', 'leave_page',
            '<%=path%>/com/leave/list?viewtype=${viewtype}',
            ['请假人员',"请假类别",'请假天数',"请假日期",<c:if test="${viewtype==1}">"审批人",</c:if><c:if test="${viewtype==3}">"是否完成休假",</c:if>"操作","id"],
            [
              {name:'leaveUser',index:'leaveUser', width:100,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              {name:'leaveType',index:'leaveType', width:100,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              {name:'leaveDayNum',index:'leaveDayNum', width:100,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              {name:'leaveDate',index:'leaveDate', width:200,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              <c:if test="${viewtype==1}">
              {name:'editor',index:'editor', width:100,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              </c:if>
              <c:if test="${viewtype==3}">
              {name:'isComplete',index:'isComplete', width:100,search:true,sortable:true, searchoptions: {sopt: ['cn']}},
              </c:if>
              {name:'act',index:'act', width:210,sortable:false,search:false,fixed:true,formatter: actFormat},
              {name:'id',index:'id',search:false,hidden:true}
            ],
            true,true
    );
  }

  function actFormat(cellvalue, options, rowObject){
    var id = rowObject.id;
    cellvalue = '<button class="btn btn-white btn-sm" onclick="fn_leave_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';
    <c:if test="${viewtype==2}">
    cellvalue += '<button class="btn btn-white btn-sm" onclick="fn_leave_finish(\'' + id + '\');"><i class="ti-back-right"> </i> 完成</button>';
    </c:if>
    return cellvalue;
  }

  function fn_leave_read(id) {
    loadURL('<%=path%>/com/leave/read?keyId='+id+'&viewtype=${viewtype}', $('#page-content'));
  }

  $("#btn_add_leave").click(function(){
    loadURL('<%=path%>/com/leave/input', $('#page-content'));
  });

  //完成操作
  function fn_leave_finish(id){
    __ajax_get("<%=path%>/com/leave/checkUser",{keyId:id},function(data){
      if(data.state==1){

        var url = '<%=path%>/com/leave/leaveFinishPage?keyId='+id;
        __open_dialog_form('请假完成', url, function (dialogRef) {
          var callback = function (data) {
            if (data) {
              dialogRef.close();
              $('#leave_table').jqGrid().setGridParam({datatype:'json'}).trigger('reloadGrid');
            } else {
              dialogRef.enableButtons();
            }
          };
          if (fn_leave_finish_save(callback) === false) {
            dialogRef.enableButtons();
          }
        });

      }else{
        __toastr_error(data.message);
      }
    })
  }

</script>